package com.summer.framework.core.category;

import com.fasterxml.jackson.databind.ser.SerializerFactory;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Description:
 *
 * @auther Ice Yang
 * Date 2025/9/30 14:38
 */
@Configuration
@ComponentScan(basePackages = "com.summer.framework.core.category")
public class JacksonConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer(CategorySerializerModifier modifier) {
        return builder -> {
            builder.postConfigurer(objectMapper -> {
                // 获取当前的SerializerFactory并设置Modifier
                SerializerFactory factory = objectMapper.getSerializerFactory();
                factory = factory.withSerializerModifier(modifier);
                objectMapper.setSerializerFactory(factory);
            });
        };
    }

}
